// router.js
import {
	RouterMount,
	createRouter
} from './js_sdk/hhyang-uni-simple-router/uni-simple-router.js';
// } from 'uni-simple-router';

const router = createRouter({
	platform: process.env.VUE_APP_PLATFORM,
	routes: [...ROUTES]
});
// 全局路由后置守卫
router.afterEach((to, from) => {
	console.log('跳转结束')
})
router.beforeEach((to, from, next) => {
	//判断是否登录
	// 测试
	// uni.setStorageSync('uid', 11);
	// uni.setStorageSync('nickname', 'xun');
	// uni.setStorageSync('openid', 'odYrE4gjyWDhHL3_nKmM0mhAIUY7');
	// uni.setStorageSync('avatar', 'https://thirdwx.qlogo.cn/mmopen/vi_32/POgEwh4mIHO4nibH0KlMECNjjGxQUq24ZEaGT4poC6icRiccVGKSyXwibcPq4BWmiaIGuG1icwxaQX6grC9VemZoJ8rg/132');
	// uni.setStorageSync('is_login', 1);
	
	if (to.path == '/pages/user/signup') {
		return next();
	}
	
    if (!uni.getStorageSync("is_login") || !uni.getStorageSync("uid")) {
		uni.setStorageSync('redirect_url', from.path);
		if (to.path !== '/pages/user/signin') {
			return next({
			   path:'/pages/user/signin',
			   NAVTYPE:'push'
			});
		}
        next()
    } else {
        next()
    }
});
export {
	router,
	RouterMount
}
